package com.group_e.Bubble.client;

//import java.io.IOException;
//import java.io.PrintWriter;
//import javax.servlet.http.*;

//import com.google.appengine.api.datastore.Query;
//import com.google.appengine.api.rdbms.AppEngineDriver;
import java.sql.*;


public class ArchiveOperate 
{
	private Connection con;
	private String User_ID;

	public ArchiveOperate(Connection con, String User_ID) 
	{
		this.con = con;
		this.User_ID = User_ID;
	}
	
	public ResultSet queryAllArchive() throws SQLException
	{
		String sql = "SELECT ARCHIVE_ID FROM Archive WHERE USER_ID = "+User_ID;

		ResultSet rs = null;
		Statement stmt = null;
		try {
			stmt = con.createStatement();
			rs = stmt.executeQuery(sql);
		}
		catch (SQLException e) {
	        e.printStackTrace();
	    }
		finally {
			if (stmt != null) {
				stmt.close();
				}
			}
		
		return rs;		
	}
	
	// for add an entry
		public ResultSet addArchive(Long A_ID, String name) throws SQLException
		{
			String sql = "INSERT INTO Archive ("+User_ID+", "+A_ID+", "+name+"); ";

			ResultSet rs = null;
			Statement stmt = null;
			try {
				stmt = con.createStatement();
				rs = stmt.executeQuery(sql);
			}
			catch (SQLException e) {
		        e.printStackTrace();
		    }
			finally {
				if (stmt != null) {
					stmt.close();
					}
				}
			
			return rs;
		}
		
		
		public ResultSet removeArchive(Long A_ID) throws SQLException
		{

			String sql = "DELETE * FROM Archive WHERE ARCHIVE_TASK_USER_ID = "+User_ID+" AND ARCHIVE_TASK_ID = "+A_ID+";";
			ResultSet rs = null;
			Statement stmt = null;
			try {
				stmt = con.createStatement();
				rs = stmt.executeQuery(sql);
			}
			catch (SQLException e) {
		        e.printStackTrace();
		    }
			finally {
				if (stmt != null) {
					stmt.close();
					}
				}
			
			return rs;
		}

}
